Imports System.Xml.Serialization
Imports ToDoList.Model.TaskQuery

Namespace Model
  <XmlType("TASK")> _
  Public Class Task
    Inherits TaskContainer

    Public Function GetDueDate() As Date
      Return DateTime.FromOADate(DueDate)
    End Function

    Public Sub SetDueDate(ByVal value As Date)
      DueDate = value.ToOADate()
    End Sub

    ''' <summary>
    ''' Do a query on the task and child tasks
    ''' </summary>
    ''' <param name="query">the query</param>
    Public Sub Query(ByVal query As AbstractTaskQuery)

      If TypeOf Me Is Task Then
        query.Inspect(Me)
      End If

      If Not query.Success Then
        For Each lTask As Task In Me.Tasks
          lTask.Query(query)
          If query.Success Then
            Exit For
          End If
        Next
      End If

    End Sub


#Region "Serialized properties"

    Private mTasks As Task() = New Task() {}
    <XmlElement("TASK")> _
    Public Property Tasks() As Task()
      Get
        Return mTasks
      End Get
      Set(ByVal value As Task())
        mTasks = value
      End Set
    End Property

    ''' <summary>
    ''' See description in base class. This property is 
    ''' for internal use in the base class (and does as such 
    ''' reflect bad design)
    ''' </summary>
    Public Overrides Property ChildTasks() As Task()
      Get
        Return mTasks
      End Get
      Set(ByVal value As Task())
        mTasks = value
      End Set
    End Property

    Private mRecurrence As Recurrence
    <XmlElement("RECURRENCE")> _
    Public Property Recurrence() As Recurrence
      Get
        Return mRecurrence
      End Get
      Set(ByVal value As Recurrence)
        mRecurrence = value
      End Set
    End Property

    Private mId As Integer
    <XmlAttribute("ID")> _
    Public Property Id() As Integer
      Get
        Return mId
      End Get
      Set(ByVal value As Integer)
        mId = value
      End Set
    End Property

    Private mPriorityColor As Integer
    <XmlAttribute("PRIORITYCOLOR")> _
    Public Property PriorityColor() As Integer
      Get
        Return mPriorityColor
      End Get
      Set(ByVal value As Integer)
        mPriorityColor = value
      End Set
    End Property

    Private mStartDateString As String
    <XmlAttribute("STARTDATESTRING")> _
    Public Property StartDateString() As String
      Get
        Return mStartDateString
      End Get
      Set(ByVal value As String)
        mStartDateString = value
      End Set
    End Property

    Private mRisk As Integer
    <XmlAttribute("RISK")> _
    Public Property Risk() As Integer
      Get
        Return mRisk
      End Get
      Set(ByVal value As Integer)
        mRisk = value
      End Set
    End Property

    Private mLastModifiedString As String
    <XmlAttribute("LASTMODSTRING")> _
    Public Property LastModifiedString() As String
      Get
        Return mLastModifiedString
      End Get
      Set(ByVal value As String)
        mLastModifiedString = value
      End Set
    End Property

    Private mPriority As Integer
    <XmlAttribute("PRIORITY")> _
    Public Property Priority() As Integer
      Get
        Return mPriority
      End Get
      Set(ByVal value As Integer)
        mPriority = value
      End Set
    End Property

    Private mAllocatedBy As String
    <XmlAttribute("ALLOCATEDBY")> _
    Public Property AllocatedBy() As String
      Get
        Return mAllocatedBy
      End Get
      Set(ByVal value As String)
        mAllocatedBy = value
      End Set
    End Property

    Private mLastModified As Double
    <XmlAttribute("LASTMOD")> _
    Public Property LastModified() As Double
      Get
        Return mLastModified
      End Get
      Set(ByVal value As Double)
        mLastModified = value
      End Set
    End Property

    Private mCreationDateString As String
    <XmlAttribute("CREATIONDATESTRING")> _
    Public Property CreationDateString() As String
      Get
        Return mCreationDateString
      End Get
      Set(ByVal value As String)
        mCreationDateString = value
      End Set
    End Property

    Private mTitle As String
    <XmlAttribute("TITLE")> _
    Public Property Title() As String
      Get
        Return mTitle
      End Get
      Set(ByVal value As String)
        mTitle = value
      End Set
    End Property

    Private mCreationDate As Double
    <XmlAttribute("CREATIONDATE")> _
    Public Property CreationDate() As Double
      Get
        Return mCreationDate
      End Get
      Set(ByVal value As Double)
        mCreationDate = value
      End Set
    End Property

    Private mPriorityWebColor As String
    <XmlAttribute("PRIORITYWEBCOLOR")> _
    Public Property PriorityWebColor() As String
      Get
        Return mPriorityWebColor
      End Get
      Set(ByVal value As String)
        mPriorityWebColor = value
      End Set
    End Property

    Private mPercentDone As Integer
    <XmlAttribute("PERCENTDONE")> _
    Public Property PercentDone() As Integer
      Get
        Return mPercentDone
      End Get
      Set(ByVal value As Integer)
        mPercentDone = value
      End Set
    End Property

    Private mStartDate As Double
    <XmlAttribute("STARTDATE")> _
    Public Property StartDate() As Double
      Get
        Return mStartDate
      End Get
      Set(ByVal value As Double)
        mStartDate = value
      End Set
    End Property

    Private mPos As Integer
    <XmlAttribute("POS")> _
    Public Property Position() As Integer
      Get
        Return mPos
      End Get
      Set(ByVal value As Integer)
        mPos = value
      End Set
    End Property

    Private mStatus As String
    <XmlAttribute("STATUS")> _
    Public Property Status() As String
      Get
        Return mStatus
      End Get
      Set(ByVal value As String)
        mStatus = value
      End Set
    End Property

    Private mNumPerson As Integer
    <XmlAttribute("NUMPERSON")> _
    Public Property NumPerson() As Integer
      Get
        Return mNumPerson
      End Get
      Set(ByVal value As Integer)
        mNumPerson = value
      End Set
    End Property

    Private mCalcPercentDone As Integer
    <XmlAttribute("CALCPERCENTDONE")> _
        Public Property CalcPercentDone() As Integer
      Get
        Return mCalcPercentDone
      End Get
      Set(ByVal value As Integer)
        mCalcPercentDone = value
      End Set
    End Property

    Private mPerson As String
    <XmlAttribute("PERSON")> _
    Public Property Person() As String
      Get
        Return mPerson
      End Get
      Set(ByVal value As String)
        mPerson = value
      End Set
    End Property
    Private mPerson1 As String
    <XmlAttribute("PERSON1")> _
    Public Property Person1() As String
      Get
        Return mPerson1
      End Get
      Set(ByVal value As String)
        mPerson1 = value
      End Set
    End Property
    Private mPerson2 As String
    <XmlAttribute("PERSON2")> _
    Public Property Person2() As String
      Get
        Return mPerson2
      End Get
      Set(ByVal value As String)
        mPerson2 = value
      End Set
    End Property
    Private mPerson3 As String
    <XmlAttribute("PERSON3")> _
    Public Property Person3() As String
      Get
        Return mPerson3
      End Get
      Set(ByVal value As String)
        mPerson3 = value
      End Set
    End Property

    Private mTimeSpentUnits As String
    <XmlAttribute("TIMESPENTUNITS")> _
    Public Property TimeSpentUnits() As String
      Get
        Return mTimeSpentUnits
      End Get
      Set(ByVal value As String)
        mTimeSpentUnits = value
      End Set
    End Property

    Private mExternalId As String
    <XmlAttribute("EXTERNALID")> _
    Public Property ExternalId() As String
      Get
        Return mExternalId
      End Get
      Set(ByVal value As String)
        mExternalId = value
      End Set
    End Property

    Private mTimeEstUnits As String
    <XmlAttribute("TIMEESTUNITS")> _
    Public Property TimeEstUnits() As String
      Get
        Return mTimeEstUnits
      End Get
      Set(ByVal value As String)
        mTimeEstUnits = value
      End Set
    End Property

    Private mCalcTimeEstimate As Double
    <XmlAttribute("CALCTIMEESTIMATE")> _
    Public Property CalcTimeEstimate() As Double
      Get
        Return mCalcTimeEstimate
      End Get
      Set(ByVal value As Double)
        mCalcTimeEstimate = value
      End Set
    End Property

    Private mTimeEstimate As Double
    <XmlAttribute("TIMEESTIMATE")> _
    Public Property TimeEstimate() As Double
      Get
        Return mTimeEstimate
      End Get
      Set(ByVal value As Double)
        mTimeEstimate = value
      End Set
    End Property

    Private mCalcTimeSpent As Double
    <XmlAttribute("CALCTIMESPENT")> _
    Public Property CalcTimeSpent() As Double
      Get
        Return mCalcTimeSpent
      End Get
      Set(ByVal value As Double)
        mCalcTimeSpent = value
      End Set
    End Property

    Private mNumCategory As Integer
    <XmlAttribute("NUMCATEGORY")> _
    Public Property NumCategory() As Integer
      Get
        Return mNumCategory
      End Get
      Set(ByVal value As Integer)
        mNumCategory = value
      End Set
    End Property

    Private mCategory As String
    <XmlAttribute("CATEGORY")> _
    Public Property Category() As String
      Get
        Return mCategory
      End Get
      Set(ByVal value As String)
        mCategory = value
      End Set
    End Property

    Private mCategory1 As String
    <XmlAttribute("CATEGORY1")> _
    Public Property Category1() As String
      Get
        Return mCategory1
      End Get
      Set(ByVal value As String)
        mCategory1 = value
      End Set
    End Property

    Private mCategory2 As String
    <XmlAttribute("CATEGORY2")> _
    Public Property Category2() As String
      Get
        Return mCategory2
      End Get
      Set(ByVal value As String)
        mCategory2 = value
      End Set
    End Property

    Private mCategory3 As String
    <XmlAttribute("CATEGORY3")> _
    Public Property Category3() As String
      Get
        Return mCategory3
      End Get
      Set(ByVal value As String)
        mCategory3 = value
      End Set
    End Property

    Private mCommentsType As String
    <XmlAttribute("COMMENTSTYPE")> _
    Public Property CommentsType() As String
      Get
        Return mCommentsType
      End Get
      Set(ByVal value As String)
        mCommentsType = value
      End Set
    End Property

    Private mVersion As String
    <XmlAttribute("VERSION")> _
    Public Property Version() As String
      Get
        Return mVersion
      End Get
      Set(ByVal value As String)
        mVersion = value
      End Set
    End Property

    Private mComments As String
    <XmlAttribute("COMMENTS")> _
    Public Property Comments() As String
      Get
        Return mComments
      End Get
      Set(ByVal value As String)
        mComments = value
      End Set
    End Property

    Private mTimeSpent As Double
    <XmlAttribute("TIMESPENT")> _
    Public Property TimeSpent() As Double
      Get
        Return mTimeSpent
      End Get
      Set(ByVal value As Double)
        mTimeSpent = value
      End Set
    End Property

    Private mFileRefPath As String
    <XmlAttribute("FILEREFPATH")> _
    Public Property FileRefPath() As String
      Get
        Return mFileRefPath
      End Get
      Set(ByVal value As String)
        mFileRefPath = value
      End Set
    End Property

    Private mCost As Double
    <XmlAttribute("COST")> _
    Public Property Cost() As Double
      Get
        Return mCost
      End Get
      Set(ByVal value As Double)
        mCost = value
      End Set
    End Property

    Private mCalcCost As Double
    <XmlAttribute("CALCCOST")> _
    Public Property CalcCost() As Double
      Get
        Return mCalcCost
      End Get
      Set(ByVal value As Double)
        mCalcCost = value
      End Set
    End Property

    Private mDepends As String
    <XmlAttribute("DEPENDS")> _
    Public Property Depends() As String
      Get
        Return mDepends
      End Get
      Set(ByVal value As String)
        mDepends = value
      End Set
    End Property

    Private mDoneDateString As String
    <XmlAttribute("DONEDATESTRING")> _
    Public Property DoneDateString() As String
      Get
        Return mDoneDateString
      End Get
      Set(ByVal value As String)
        mDoneDateString = value
      End Set
    End Property

    Private mDoneDate As Double
    <XmlAttribute("DONEDATE")> _
    Public Property DoneDate() As Double
      Get
        Return mDoneDate
      End Get
      Set(ByVal value As Double)
        mDoneDate = value
      End Set
    End Property

    Private mDueDate As Double
    <XmlAttribute("DUEDATE")> _
    Public Property DueDate() As Double
      Get
        Return mDueDate
      End Get
      Set(ByVal value As Double)
        mDueDate = value
      End Set
    End Property

    Private mDueDateString As String
    <XmlAttribute("DUEDATESTRING")> _
    Public Property DueDateString() As String
      Get
        Return mDueDateString
      End Get
      Set(ByVal value As String)
        mDueDateString = value
      End Set
    End Property

#End Region

  End Class
End Namespace

